#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 1000010  

int heap[MAX_SIZE];     
int heap_size = 0;      

void swim(int i) 
{
    int temp = heap[i];  
    while (i > 0) 
    {
        int parent = (i - 1) / 2;  
        if (temp < heap[parent])
        {
            heap[i] = heap[parent]; 
            i = parent;
        }
        else 
        {
            break;
        }
    }
    heap[i] = temp;  
}

void sink(int i) 
{
    int temp = heap[i];  
    while (2 * i + 1 < heap_size)
    { 
        int left = 2 * i + 1;        
        int right = left + 1;         
        int min_child = left;        

        if (right < heap_size && heap[right] < heap[left]) 
        {
            min_child = right;
        }

        if (heap[min_child] < temp)
        {
            heap[i] = heap[min_child];  
            i = min_child;
        }
        else 
        {
            break;
        }
    }
    heap[i] = temp;  
}

void insert(int x) 
{
    heap[heap_size] = x; 
    swim(heap_size);      
    heap_size++; 
}

void delete_min() 
{
    heap[0] = heap[heap_size - 1];  
    heap_size--;   
    if (heap_size > 0) 
    {
        sink(0);  
    }
}

int get_min() 
{
    return heap[0];
}

int main() 
{
    int n;
    scanf_s("%d", &n); 

    for (int i = 0; i < n; i++) 
    {
        int op;
        scanf_s("%d", &op);  

        if (op == 1) 
        {
            int x;
            scanf_s("%d", &x);
            insert(x);
        }
        else if (op == 2) 
        {
            printf("%d\n", get_min());
        }
        else if (op == 3) 
        {
            delete_min();
        }
    }

    return 0;
}